﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using JM.JCY.BusinessEntity;
using JM.JCY.Proxy;
using NCS.IConnect.ApplicationContexts;
using JM.JCY.Common;
using JM.JCY.Common.Utilities;
using Microsoft.SharePoint;

namespace JM.JCY.SharePointComponent.LawArchives.CreateLawCaseMaterial
{
    public partial class CreateLawCaseMaterialUserControl : UserControl
    {
        public string _userName
        {
            set { ViewState["_userName"] = value; }
            get { return (string)ViewState["_userName"]; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (ApplicationContext.Current.UserName != null)
            {
                _userName = ApplicationContext.Current.UserName;
            }

            if (!IsPostBack)
            {
                //this.txtFiller.Text = _userName;
            }

        }

        protected void imgSubmit_Click(object sender, ImageClickEventArgs e)
        {
            using (LawCaseProxy proxy = new LawCaseProxy())
            {
                var newDT = new LawCaseDataSet.T_LawCaseMaterialDataTable();
                var newRow = newDT.NewT_LawCaseMaterialRow();

                newRow.HandBy = this.txtHandBy.Text;
                newRow.HandDate = this.dtHandDate.SelectedDate;
                newRow.StuffName = this.txtStuffName.Text;
                newRow.StuffCount = Int32.Parse(this.txtStuffCount.Text);
                newRow.InvolvedBy = this.txtInvolvedBy.Text;
                newRow.BuildDate = this.dtBuildDate.SelectedDate;
                newRow.HandlelSituation = this.txtHandlelSituation.Text;
                newRow.HandleDate = this.dtHandleDate.SelectedDate;
                newRow.TurnOverDate = this.dtTurnOverDate.SelectedDate;
                newRow.ReturnDate = this.dtReturnDate.SelectedDate;
                newRow.ReceiveBy = this.txtReceiveBy.Text;
                newRow.Others = this.txtOthers.Text;
                newRow.Remark = this.txtRemark.Text;

                newRow.FillDept = this.txtFillDept.Text;
                newRow.Filler = this.txtFiller.Text;
                newRow.Year = this.txtYear.Text;

                JCYUtility.UpdateCommonFields(newRow, "Iori");
                newDT.AddT_LawCaseMaterialRow(newRow);
                proxy.UpdateLawCaseMaterial(newDT);
            }

            Response.Redirect("LawCaseMaterial.aspx");
        }

        protected void imgCancel_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("LawCaseMaterial.aspx");
        }
    }
}
